%%
clear all;
% 生成 D个中继器
D=20;
%总共有 NP 个解
NP=100;
%范围为 N*N的位置
N=60;
DT=20;% 距离DT后中继器不能识别
P=5;%假设P个任务点
count=1;
a=1;
near_location=5; % 后面代码也要改

% 任务点对应位置；
location_TU=N*rand(P,2); % 现在考虑多个，假设P个任务点
% EOC对应位置
location_EOC=[N,N];

while count<=NP % 达到NP个解   
    
% 初始化中继器对应位置
location_RU=N*rand(D,2); 
location_RU(1,:)=location_TU(1,:)+2*near_location*rand(1,2); % near_location需要修改 *2 扩大范围
judge=judgement(location_TU,P,location_RU,location_EOC,DT);

a=a+1;%% 总共迭代次数
if judge==1
    location_NP(:,:,count)=location_RU; % 对应NP个有效解， 为D*2*NP 维
    count=count+1;
end


end

%% 画图
result=ABC(location_TU,location_NP,location_EOC,DT,N);
size(result)
scatter(result(:,1),result(:,2),'fill');
hold on
grid on
scatter(location_EOC(:,1),location_EOC(:,2),'y','fill');
scatter(location_TU(:,1),location_TU(:,2),'R','fill');
legend('中继器' ,' EOC','任务点');
center=ones(size(result,1),1)*DT;
viscircles(result,center,'LineWidth',1);
center_TU=ones(size(location_TU,1),1)*near_location;
viscircles(location_TU,center_TU,'Color','k','LineWidth',1,'LineStyle','--');
hold off;



